<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">

    </div>
    <button>加一项</button>
    <script>
        let oBox = document.getElementsByClassName('box')[0];
        let oBtn = document.getElementsByTagName('button')[0];
        oBtn.addEventListener('click', function() {
            numProxy.push(numList.length)
        })
        let numList = [0, 1, 2, 3, 4];
        let render = {
            init: function() {
                const fragment = document.createDocumentFragment();
                for (let i of numList) {
                    const item = document.createElement('p');
                    item.innerHTML = i;
                    fragment.appendChild(item)
                };
                oBox.appendChild(fragment)
            },
            pushChange: function(val) {
                const item = document.createElement('p');
                item.innerHTML = val;
                oBox.appendChild(item)
            }
        }
        let numProxy = new Proxy(numList, {
            get(target, key, receiver) {
                return Reflect.get(target, key, receiver)
            },
            set(target, key, value, receiver) {
                if (key !== 'length') {
                    render.pushChange(value)
                }
                return Reflect.set(target, key, value, receiver)
            }
        })
        render.init()
    </script>
</body>

</html>